package com.zdft.promotion.rabbitmq.service.impl;

import com.zdft.promotion.asyn.service.api.IAsynDealService;
import com.zdft.promotion.rabbitmq.domain.QueueEnum;
import com.zdft.promotion.rabbitmq.model.PushModel;
import com.zdft.promotion.rabbitmq.service.api.IMesssageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class MessageServiceImpl implements IMesssageService {

    private static Logger LOGGER = LoggerFactory.getLogger(MessageServiceImpl.class);

    @Autowired
    AmqpTemplate amqpTemplate;
    @Autowired
    IAsynDealService asynDealService;


    @Override
    public void addOrderMessageToQueue(PushModel model, QueueEnum queueEnum) {
        amqpTemplate.convertAndSend(queueEnum.getExchange(), queueEnum.getRouteKey(), model);
    }

    @Override
    public void addOrderMessageToQueue(List<PushModel> modelList, QueueEnum queueEnum) {
        if (!CollectionUtils.isEmpty(modelList)) {
            for (PushModel model : modelList) {
                addOrderMessageToQueue(model, queueEnum);
            }
        }
    }

    @Override
    public boolean messageConsumer(PushModel model) {
        //是否需要重新插入队列，再次执行
        boolean requeue = false;
        if (model != null) {
            switch (model.getType().intValue()) {
                case 100:
                    break;
                default:
                    LOGGER.info("*************传入类型" + model.getType() + "缺少对应，请检查***************");
                    break;
            }
        }
        return requeue;
    }
}
